﻿using Noria.Web.Utility;

namespace Noria.Web.MyMSDN.Tasks
{
    internal class HeartBeatTask : NTask
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        private static readonly int delay = (int)NConfig.Root.heartbeat.scheduler.delay * 60 * 1000;
        private static readonly string target = (string)NConfig.Root.heartbeat.settings.godaddy;

        protected override bool Enabled()
        {
            return (bool)NConfig.Root.heartbeat.enabled;
        }

        protected override void Execute()
        {
            HttpBot.RequestNonQuery(null, target);
            log.DebugFormat("Ping {0} ...", target);
        }

        protected override int GetNextOccurrenceSleeping()
        {
            return delay;
        }
    }
}